package br.skytef.stmanager.daos;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import br.skytef.stmanager.entities.SubErroEntity;
import br.skytef.stmanager.utils.Pool;

public class SubErroDao {

	/**
	 * Variável para conexão, obtido através de um Pool(br.skytef.stmanager.utils.Pool)
	 */
	private static Connection conexao = null;	
	
	private static String erro;
	public static String getErro() {return erro;}


	/**
	 * Inserir nova SubErro
	 * @param SubErro
	 */
	
	public List <SubErroEntity> listar(){
		List <SubErroEntity> suberros = null;
		SubErroEntity suberro;
		try {
			conexao = Pool.getConnection();
			Statement st = conexao.createStatement();
			ResultSet rs = st.executeQuery("SELECT * FROM subErro order by nome");
			if (rs.next()) {   
				suberros = new ArrayList<SubErroEntity>();
				do {                      
					suberro = new SubErroEntity();
					suberro.setId((rs.getInt("id")));
					suberro.setNome((rs.getString("nome")));
					suberros.add(suberro);  
				} while (rs.next());
			}
			conexao.close();
		} catch (SQLException e) {
			System.out.println("SQL erro: "+ e);
		} catch (Exception e) {
			System.out.println("Geral erro: "+ e);
		}
		return suberros;		
	}

}
